package org.agent.aigccore.model.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一响应对象
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "统一响应对象")
public class Response<T> {
    
    /**
     * 请求是否成功
     */
    @Schema(description = "请求是否成功", example = "true")
    private boolean success;
    
    /**
     * 响应消息
     */
    @Schema(description = "响应消息", example = "操作成功")
    private String message;
    
    /**
     * 错误码，成功时为null
     */
    @Schema(description = "错误码", example = "SUCCESS")
    private String errorCode;
    
    /**
     * 响应数据
     */
    @Schema(description = "响应数据")
    private T data;
    
    /**
     * 请求路径
     */
    @Schema(description = "请求路径", example = "/api/auth/login")
    private String path;
    
    /**
     * 响应时间戳
     */
    @Schema(description = "响应时间戳", example = "1704067200000")
    private long timestamp;
    
    /**
     * 创建成功响应
     * 
     * @param data 响应数据
     * @param <T> 数据类型
     * @return 成功响应对象
     */
    public static <T> Response<T> success(T data) {
        Response<T> response = new Response<>();
        response.setSuccess(true);
        response.setMessage("操作成功");
        response.setData(data);
        response.setTimestamp(System.currentTimeMillis());
        return response;
    }
    
    /**
     * 创建成功响应
     * 
     * @param data 响应数据
     * @param message 响应消息
     * @param <T> 数据类型
     * @return 成功响应对象
     */
    public static <T> Response<T> success(T data, String message) {
        Response<T> response = success(data);
        response.setMessage(message);
        return response;
    }
    
    /**
     * 创建失败响应
     * 
     * @param errorCode 错误码
     * @param message 错误消息
     * @param <T> 数据类型
     * @return 失败响应对象
     */
    public static <T> Response<T> fail(String errorCode, String message) {
        Response<T> response = new Response<>();
        response.setSuccess(false);
        response.setMessage(message);
        response.setErrorCode(errorCode);
        response.setTimestamp(System.currentTimeMillis());
        return response;
    }
    
    /**
     * 设置请求路径
     * 
     * @param path 请求路径
     * @return 当前响应对象
     */
    public Response<T> withPath(String path) {
        this.setPath(path);
        return this;
    }
}